import React, {FC, LazyExoticComponent, Suspense} from 'react';

type LazyImportComponentProps<P = NonNullable<unknown>> = {
    lazyChildren: LazyExoticComponent<(props: P) => Element>;
    lazyChildrenProps?: P;
};

const LazyImportComponent:FC = <P,>({ lazyChildren: LazyChild, lazyChildrenProps }: LazyImportComponentProps<P>) => {
    return (
        <Suspense fallback={<div>Loading...</div>}>
            <LazyChild {...(lazyChildrenProps as P)} />
        </Suspense>
    );
};

export default LazyImportComponent;
